<?php namespace Home\Controller; 

use Hdphp\Controller\Controller;

//测试控制器
class LoginController extends Controller{
private $userModel;
	//构造函数
	public function __init()
	{
	$this->userModel = new \Common\Model\Homeuser;
		
	}
	
    //动作
   public function zhuce(){
// 
		if(IS_POST){
			p($_POST);
			if($this->userModel->store()){
				View::success('注册成功',U('Login/Login'));
			}else{
				View::error($this->userModel->getError());
			}
			
			
		}
		
		View::make();
	}
	
	public function Login(){
		
		if(IS_POST){
			
		
		
		$phone=Q('post.phone');
		
		$password=Q('post.password','','md5');
		
		$Model=new \Common\Model\Homeuser;
		
		$data=$Model->where("phone = '{$phone}'")->find();
		
		if(!$data) View::error('用户名不存在');
		
		if($data['password'] != $password)View::error('用户名或密码错误');
		
		$_SESSION['uid']=$data['uid'];
		$_SESSION['phone']=$data['phone'];
		
		View::success('登陆成功',U('Index/index'));
		}
		
		View::make();
	}
	
	
	
	
		
	public function code(){
	   Code::make();
	   
	}
	
	
	
	
	
}
